package com.dao.impl;
// default package

import static org.hibernate.criterion.Example.create;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.dao.ApplyDao;
import com.model.Apply;
import com.util.Pagination;

/**
 	* A data access object (DAO) providing persistence and search support for Apply entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see .Apply
  * @author MyEclipse Persistence Tools 
 */
@Repository("ApplyDao")
public class ApplyDaoImpl implements ApplyDao {
	@Resource
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

    public void save(Apply transientInstance) {
        try {
        	Session session = sessionFactory.getCurrentSession();
            session.save(transientInstance);
        } catch (RuntimeException re) {
            throw re;
        }
    }
    
	public void delete(Apply persistentInstance) {
        try {
        	Session session = sessionFactory.getCurrentSession();
            session.delete(persistentInstance);
        } catch (RuntimeException re) {
            throw re;
        }
    }
    
    public Apply findById( java.lang.Integer id) {
        try {
        	Session session = sessionFactory.getCurrentSession();
            Apply instance = (Apply) session
                    .get("com.model.Apply", id);
            return instance;
        } catch (RuntimeException re) {
            throw re;
        }
    }
    
    
    public List<Apply> findByExample(Apply instance) {
        try {
        	Session session = sessionFactory.getCurrentSession();
            List<Apply> results = (List<Apply>) session
                    .createCriteria("com.model.Apply")
                    .add( create(instance) )
            .list();
            return results;
        } catch (RuntimeException re) {
            throw re;
        }
    }    
    


	public List findAll() {
		try {
			Session session = sessionFactory.getCurrentSession();
			String queryString = "from Apply";
	         Query queryObject = session.createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
    public Apply merge(Apply detachedInstance) {
        try {
        	Session session = sessionFactory.getCurrentSession();
            Apply result = (Apply) session
                    .merge(detachedInstance);
            return result;
        } catch (RuntimeException re) {
            throw re;
        }
    }
    
    public List<Apply> getApplyList(Apply apply, Pagination page) {
    	Session session = sessionFactory.getCurrentSession();
    	List<Apply> results = (List<Apply>) session
                   .createCriteria("com.model.Apply")
                   .add( create(apply) ).setFirstResult((page.getCurrentpage()-1)*page.getPagesize()-1).setMaxResults(page.getPagesize())
           .list();
    	
           return results;
       
    	
    }

    
}